// 封装文章接口
import axios from '@/utils/request'
/**
 *
 * @param {Number} channelId 频道ID
 * @param {*} timestamp 时间戳
 * @returns
 */
export const getArticleList = (channelId, timestamp) =>
  axios({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })

/**
 * 对文章不喜欢
 * @param {*} target 不喜欢的文章id
 * @returns
 */
export const articleDisLike = (target) =>
  axios({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })

/**
 * 举报文章
 * @param {*} target 文章id
 * @param {*} type 举报类型
 * @returns
 */
export const articleReport = (target, type) =>
  axios({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: {
      target,
      type
    }
  })

/**
 * 获取文章详情
 * @param {*} artId 文章id
 * @returns
 */
export const getArticleDetail = (artId) =>
  axios({
    url: '/v1_0/articles/' + artId
  })

/**
 * 关注文章用户
 * @param {*} target 关注文章用户的id
 * @returns
 */
export const followUser = (target) =>
  axios({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })

/**
 * 取消关注文章用户
 * @param {*} target 取消关注文章用户的id
 * @returns
 */
export const unfollowUser = (target) =>
  axios({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = (id) => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = (id) => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = (id) => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = (id) => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
/**
 * 获取对文章的评论
 * @param {*} source 文章id
 * @param {*} offset 偏移量 获取第几页数据
 * @returns
 */
export const getArticleCommon = (source, offset) =>
  axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })

/**
 * 发表评论
 * @param {*} target 评论文章的id
 * @param {*} content 评论内容
 * @returns
 */
export const addArticleCommon = (target, content) =>
  axios({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target,
      content
    }
  })

/**
 * 评论点赞
 * @param {*} target 评论id
 * @returns
 */
export const likeCommon = (target) =>
  axios({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target
    }
  })

/**
 * 取消评论点赞
 * @param {*} target 评论id
 * @returns
 */
export const unlikeCommon = (target) =>
  axios({
    method: 'DELETE',
    url: '/v1_0/comment/likings/' + target
  })

/**
 * 获取回复文章的评论的评论
 * @param {*} source 评论id
 * @param {*} offset 偏移量 获取第几页数据
 * @returns
 */
export const getCommon = (source, offset) =>
  axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
/**
 * 对评论发表评论
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @returns
 */
export const addCommon = (target, content, artId) =>
  axios({
    method: 'POST',
    url: '/v1_0/comments',
    data: {
      target,
      content,
      art_id: artId
    }
  })
